home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr11 / pdox693.zip / TI542.ASC < prev    next >
Text File  |  1992-09-14  |  5KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Paradox                                NUMBER  :  542
  9.   VERSION  :  All
  10.        OS  :  DOS
  11.      DATE  :  September 14, 1992                       PAGE  :  1/3
  12.  
  13.     TITLE  :  Stack Space/PAL Allocation of Stacks
  14.  
  15.  
  16.  
  17.  
  18.   This is an explanation of why the error "Run out of stack space"
  19.   is displayed by Paradox.
  20.  
  21.   Stack space problems are the result of scripts or procedures
  22.   calling each other.  The Paradox stack is used to keep track of
  23.   the script (or procedure) active at any time and which scripts
  24.   have been played.
  25.  
  26.   The stack works on the premise that the last item placed on the
  27.   stack must be cleared before accessing any other item, sometimes
  28.   referred to as LIFO (Last In, First Out).  This means that each
  29.   new procedure you call is placed on the stack, pushing down the
  30.   previous procedure.  In order to develop an understanding of the
  31.   discussion, let's work with some examples.
  32.  
  33.   If script FIRST calls script SECOND, the stack would look like
  34.   this:
  35.  
  36.        FIRST
  37.        SECOND
  38.  
  39.   Then, SECOND calls script FIRST again and now the stack becomes:
  40.  
  41.        FIRST
  42.        SECOND
  43.        FIRST
  44.  
  45.   This can continue until all the stack space is used up.  The way
  46.   to prevent this recursive system from filling up all the stack
  47.   space, is to use the RETURN command.  Using RETURN on the stack
  48.   problem yields the following allocation of stack space:
  49.  
  50.        FIRST
  51.        SECOND
  52.  
  53.   If script SECOND uses RETURN, instead of issuing PLAY FIRST,
  54.   SECOND will be "popped off" the stack, and control returns to
  55.   script FIRST.  Now the stack looks like this:
  56.  
  57.        FIRST
  58.  
  59.   All of this information holds true whether you are using scripts
  60.   or procedures.  The use of the WHERE? (press [Ctrl-W]) command is
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Paradox                                NUMBER  :  542
  75.   VERSION  :  All
  76.        OS  :  DOS
  77.      DATE  :  September 14, 1992                       PAGE  :  2/3
  78.  
  79.     TITLE  :  Stack Space/PAL Allocation of Stacks
  80.  
  81.  
  82.  
  83.  
  84.   very useful in locating where recursion happens.  Chapter 10 of
  85.   the Paradox 4.0 PAL Reference Guide explains the usage of WHERE?.
  86.  
  87.   The following pages contain scripts demonstrating the incorrect
  88.   method and correct method for stack usage.
  89.  
  90.   release vars all
  91.   ;This script demonstrates a STACK OVERFLOW error.
  92.   ;
  93.   ;--------------What NOT to DO-----------------
  94.   Proc main()                            ;Proc starts
  95.   Showmenu                               ;a menu
  96.   "Recursive" : "play this several times (15 or 20 to get debug)",
  97.   "Quit"      : "Quit"
  98.       to z                               ;to a variable
  99.       Switch
  100.           case z = "Recursive":          ;if they select this choice
  101.              jcdowrong()                 ;call jcdowrong procedure
  102.           case z = "Quit":
  103.              message "Adios"             ;if they select quit
  104.              sleep 1000                   ;give a message
  105.       Endswitch
  106.   EndProc
  107.  
  108.   Proc jcdowrong()                       ;the bad procedure
  109.      if not isassigned(z1)
  110.      then z1 = 1
  111.      endif
  112.       Message "looped " + strval(z1)+ " times"
  113.       z1=z1+1
  114.       sleep 1000
  115.       main()                             ;this is the offending line
  116.   EndProc
  117.  
  118.   Main()                                 ;the actual script
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Paradox                                NUMBER  :  542
  141.   VERSION  :  All
  142.        OS  :  DOS
  143.      DATE  :  September 14, 1992                       PAGE  :  3/3
  144.  
  145.     TITLE  :  Stack Space/PAL Allocation of Stacks
  146.  
  147.  
  148.  
  149.  
  150.   ; Rather than call the original procedure, let the procedure
  151.   ; return naturally or use a "return" command
  152.   ;----------------What to DO------------------
  153.  
  154.   Proc goodmain()                        ;Proc starts
  155.   While(true)                            ;use the loop to eliminate
  156.   having to
  157.                                          ;to recursive calls
  158.   Showmenu                               ;a menu
  159.   "NON-Recursive" : "play this several times(15 or 20 to get debug)",
  160.                                          ;the choices
  161.   "Quit"          : "Quit"
  162.       to z                               ;to a variable
  163.       Switch
  164.           case z = "NON-Recursive":      ;if they select this choice
  165.              jcdoright()                 ;call jcdoright procedure
  166.           case z = "Quit":
  167.              message "Adios"             ;if they select quit
  168.              sleep 1000                   ;give a message
  169.              quitloop
  170.       Endswitch
  171.   endwhile
  172.   EndProc
  173.  
  174.   Proc jcdoright()
  175.      if not isassigned(z2)
  176.      then z2 = 1
  177.      endif
  178.       Message "looped " + strval(z2)+ " times"
  179.       z2=z2+1
  180.       sleep 1000
  181.   EndProc
  182.  
  183.   goodmain()
  184.  
  185.   For additional information about PAL, refer to the PAL Reference
  186.   Guide (for versions earlier than 4.0, refer to the PAL User's
  187.   Guide).
  188.  
  189.   DISCLAIMER: You have the right to use this technical information
  190.   subject to the terms of the No-Nonsense License Statement that
  191.   you received with the Borland product to which this information
  192.   pertains.
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.